/*
 * Copyright 2010-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jslet.paas.web;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.jslet.paas.modelmeta.model.ModelMeta;
import org.jslet.paas.modelmeta.model.ModelMetaConfiguration;
import org.jslet.paas.modelmeta.service.ModelMetaService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BizMetaDataController
{
	@Resource(name="modelMetaService")
	private ModelMetaService modelMetaService;
	
	@RequestMapping(method = RequestMethod.POST, value = "/metadata/findPage/{pageNum}/{pageSize}", produces = "application/json")
	public @ResponseBody
	List<ModelMeta> findPageMetaData(@PathVariable int pageNum, @PathVariable int pageSize)
	{
//		return metaService.findAllMetaData();
		return ModelMetaConfiguration.SINGLETON.getAllBoConfig();
	}

	
	@RequestMapping(method = RequestMethod.POST, value = "/metadata/find", produces = "application/json")
	public @ResponseBody
	List<ModelMeta> findAllMetaData()
	{
//		return metaService.findAllMetaData();
		return ModelMetaConfiguration.SINGLETON.getAllBoConfig();
	}

	@RequestMapping(method = RequestMethod.POST, value="/metadata/create", produces="application/json", consumes = "application/json")
	public @ResponseBody List<HashMap<String, Object>> createMetaData(@RequestBody List<HashMap<String, Object>> newData){
		return this.modelMetaService.createModelMeta(newData);
	}
	
	@RequestMapping(method = RequestMethod.POST, value="/metadata/update", produces="application/json", consumes = "application/json")
	public @ResponseBody List<HashMap<String, Object>> updateMetaData(@RequestBody List<HashMap<String, Object>> newData){
		return this.modelMetaService.createModelMeta(newData);
	}

	@RequestMapping(method = RequestMethod.POST, value="/metadata/delete", produces="application/json", consumes = "application/json")
	public @ResponseBody List<HashMap<String, Object>> deleteMetaData(@RequestBody List<HashMap<String, Object>> newData){
		return this.modelMetaService.createModelMeta(newData);
	}

}

/*
*$Log: av-env.bat,v $
*/